package com.junyidao.game.controller;

import com.junyidao.game.constant.OperLogConstant;
import com.junyidao.game.core.LoginInfo;
import com.junyidao.game.core.annotation.Action;
import com.junyidao.game.pojo.PCode;
import com.junyidao.game.pojo.TChannel;
import com.junyidao.game.service.ChannelService;
import com.junyidao.game.service.CodeService;
import com.junyidao.game.service.GameService;
import com.junyidao.game.vo.GameVo;
import com.junyidao.game.vo.TChannelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by zzh on 2016/7/13.
 */
@Controller
@RequestMapping("/game")
public class GameController extends BaseController {

    @Autowired
    private ChannelService channelService;

    @Autowired
    private CodeService codeService;

    @Autowired
    private GameService gameService;

    @RequestMapping(value = "/list")
    @Action(desc = "进入游戏添加/移除页面")
    public ModelAndView list() {
        ModelAndView result = new ModelAndView("game/list");
        List<PCode> gameType = codeService.select("GameType");
        result.addObject("gameType", gameType);
        return result;
    }

    @RequestMapping(value = "/add")
    public ModelAndView add() {
        ModelAndView result = new ModelAndView("system/game_add");
        return result;
    }

    @RequestMapping(value = "/edit")
    public ModelAndView edit() {
        ModelAndView result = new ModelAndView("system/game_edit");
        return result;
    }

    @RequestMapping(value = "/auth")
    public ModelAndView auth() {
        ModelAndView result = new ModelAndView("system/game_auth");
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/listChannel")
    @Action(desc = "获取渠道列表", sysPriv = false)
    public Map<String, Object> listChannel(TChannelVo channel) {
        channel.setUid(LoginInfo.getUser().getUid());
        List<TChannel> channelList = channelService.selectChannelByChannel(channel);
        return resultSucess(channelList);
    }

    @ResponseBody
    @RequestMapping(value = "/listGame")
    @Action(desc = "获取游戏列表", sysPriv = false)
    public Map<String, Object> listGame(GameVo gameVo, String ids) {
        Map<String, Object> map = channelService.selectGameByChannelIds(gameVo, ids);
        return resultSucess(map);
    }

    @ResponseBody
    @RequestMapping(value = "/addGame")
    @Action(operType = OperLogConstant.GAME_ADD_GAME, desc = "添加游戏", needLog = true)
    public Map<String, Object> addGame(String channelIds, String gameIds) throws Exception {
//        channelService.addGame(channelIds, gameIds);
        gameService.addGame();
        return resultSucess(null);
    }

    @ResponseBody
    @RequestMapping(value = "/delGame")
    @Action(operType = OperLogConstant.GAME_MOVE_GAME, desc = "移除游戏", needLog = true)
    public Map<String, Object> delGame(String channelIds, String gameIds) {
        channelService.delGame(channelIds, gameIds);
        return resultSucess(null);
    }


}
